#include<iostream>
using namespace std;

int arr[10];
int vis[10] = {0};
void print_one_result(int n )
{
  for(int i = 0; i < n; i++){
    if(i) cout << " ";
    cout << arr[i];
  }
  cout << endl;
}
void dfs(int ind, int n)
{
  if(ind == n)
  {
    print_one_result(n);
    return ;
  }
  for(int i = 1; i <= n; i++)
  {
    if(vis[i]) continue;
    arr[ind] = i;
    vis[i] = 1;
    dfs(ind + 1, n);
    vis[i] = 0;
  }
}


int main()
{
  int n;
  cin >> n;
  dfs(0, n);
  return 0;
}
